import os
import numpy as np


def convert_npy_to_csv(folder_path):
    for root, _, files in os.walk(folder_path):
        for file in files:
            if file.endswith('.npy'):
                npy_file_path = os.path.join(root, file)
                data = np.load(npy_file_path)
                csv_file_name = os.path.splitext(file)[0] + '.csv'
                csv_file_path = os.path.join(root, csv_file_name)
                np.savetxt(csv_file_path, data, delimiter=',')
                print(f"Converted {npy_file_path} to {csv_file_path}")


if __name__ == "__main__":
    folder_path = '.'  # 默认当前文件夹，可根据需求修改
    convert_npy_to_csv(folder_path)
